package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.resutl.PageResult;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.text.Utilities;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Description NursingProjectServiceImpl
 * @Author shuaijie LI
 * @Date 2024-08-24
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;


    @Override
    public PageResponse<NursingProjectVo> page(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProjectVo> page = nursingProjectMapper.page(name, pageNum, pageSize, status);
        PageResponse<NursingProjectVo> pageResponse = new PageResponse<>(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject bean = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        bean.setCreateBy(1671403256519078138L);
        bean.setUpdateBy(1L);
        nursingProjectMapper.addNursingProject(bean);
    }

    //根据id查询
    @Override
    public NursingProject getById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.getById(id);
        return nursingProject;
    }

    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject bean = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.updateNursingProject(bean);
    }

    //删除
    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id,status);
    }

}
